home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / MacGofer 0.22d / MacGofer Sources / mac_options.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-06  |  8.6 KB  |  350 lines  |  [TEXT/MPS ]

  1. /*****************************************************************************
  2.  
  3.   mac_options.c:  Copyright (c) Kevin Hammond 1993.   All rights reserved.
  4.   
  5.   This module handles the Macintosh options menu.
  6.  
  7. *****************************************************************************/
  8.  
  9. #include "mac.h"
  10. #include "prelude.h"
  11.  
  12. #pragma segment Options
  13.  
  14. int AutoLoad = TRUE;         /* Is autoloading on          */ 
  15. int MultiTasking = FALSE;     /* or "multitasking"          */
  16. int dummy = TRUE;        /* Dummy value for toggles array  */
  17.  
  18. extern int HeapPC;
  19.  
  20. int    Num_stack   = NUM_STACK,    Num_name    = NUM_NAME,    
  21.     Num_classes = NUM_CLASSES,  Num_insts   = NUM_INSTS,  
  22.     Num_tycon   = NUM_TYCON,    Num_tyvars  = NUM_TYVARS,
  23.     Num_addrs   = NUM_ADDRS,    Num_files   = NUM_FILES,  
  24.     Num_modules = NUM_MODULES,  Num_offsets = NUM_OFFSETS,
  25.     Num_tuples  = NUM_TUPLES,   Num_fixups  = NUM_FIXUPS, 
  26.     Num_indexes = NUM_INDEXES,  Num_syntax  = NUM_SYNTAX,  
  27.     Num_text    = NUM_TEXT,     Num_selects = NUM_SELECTS;
  28.  
  29. /*
  30.     The toggles array contains addresses of the switches controlled
  31.     by option menu commands.  These must be *ints*, which causes
  32.     some problems with the original Gofer: Bool seems to be treated
  33.     as a short!
  34. */
  35.  
  36. #if !THINKC
  37. static int *toggles[] = {
  38.     &showStats,
  39.     &gcMessages,
  40.     &addType,
  41.     &literateScripts,
  42.     &coerceNumLiterals,
  43.     &showDicts,
  44.     &traceEval,
  45.     &dummy,
  46.     &AutoLoad,
  47.     &MultiTasking
  48. };
  49. #else
  50. static int *toggles[] = {
  51.     (int *) &showStats,
  52.     (int *) &gcMessages,
  53.     (int *) &addType,
  54.     (int *) &literateScripts,
  55.     (int *) &coerceNumLiterals,
  56.     (int *) &showDicts,
  57.     (int *) &traceEval,
  58.     (int *) &dummy,
  59.     (int *) &AutoLoad,
  60.     (int *) &MultiTasking
  61. };
  62. #endif
  63.  
  64.  
  65. /*
  66.     Initialise the Options menu from the toggles array.
  67. */
  68.  
  69. InitOptionMenu()
  70. {
  71.   short i;
  72.  
  73.   for (i = 1; i <= Option_Toggle_Limit; ++i)
  74.     if(toggles[i-1]!=&dummy)
  75.       CheckItem(Menu_Option,i,(short)(*toggles[i-1]? TRUE: FALSE));
  76. }
  77.  
  78.  
  79. /*
  80.     Toggle an item, and set the appropriate flag in the Options menu.
  81. */
  82.  
  83. dotoggle(item)
  84. short item;
  85. {
  86.   short newtoggle = *toggles[item-1] = !*toggles[item-1];
  87.   CheckItem(Menu_Option,item,newtoggle);
  88. }
  89.  
  90.  
  91. /*
  92.     The evidence dialog handles evidence-related options.
  93. */
  94.  
  95. doevidencedialog()
  96. {
  97.   char evidlevel[256];
  98.   DialogPtr eviddlg;
  99.   short itemhit;
  100.   extern int maxEvidLevel;
  101.   int newEvidLevel;
  102.  
  103.   /* Set the cursor */
  104.   SetCursor(&(qd.arrow));
  105.   
  106.   /* Initialise the dialog */  
  107.   eviddlg = GetNewDialog(Res_Dlg_Evidence,nil,(WindowPtr) -1);
  108.   
  109.   /* Initialise strings */
  110.   sprintf(evidlevel,"%u",maxEvidLevel);
  111.   SetDlgItemText(eviddlg,Res_DItem_EvidDepth,evidlevel);
  112.  
  113.   /* Set Check Boxes */
  114.   SetDlgItemValue(eviddlg,Res_DItem_AnyEvidence,(short)anyEvidence);        
  115.   SetDlgItemValue(eviddlg,Res_DItem_SilentFail, (short)silentEvFail);
  116.  
  117.   /* Now show the window */  
  118.   ShowWindow(eviddlg);
  119.  
  120.   /* Highlight the default button */
  121.   highlightDefault(eviddlg);
  122.  
  123.   for(;;)
  124.     {
  125.       ModalDialog((ModalFilterProcPtr) NIL,&itemhit);
  126.       switch(itemhit)
  127.         {
  128.           case OK:
  129.             getitext(gethandle(Res_DItem_EvidDepth,eviddlg),evidlevel);
  130.  
  131.         if((newEvidLevel = atoi(evidlevel)) > 0)
  132.           {
  133.             maxEvidLevel = newEvidLevel;
  134.              anyEvidence = GetCtlValue(getctlhandle(Res_DItem_AnyEvidence,eviddlg));    
  135.               silentEvFail = GetCtlValue(getctlhandle(Res_DItem_SilentFail,eviddlg));    
  136.  
  137.         DisposDialog(eviddlg);
  138.         return;
  139.           }
  140.         else
  141.           {
  142.             SysBeep(1);
  143.                 sprintf(evidlevel,"%u",maxEvidLevel);
  144.                 SetDlgItemText(eviddlg,Res_DItem_EvidDepth,evidlevel);
  145.           }
  146.         break;
  147.            
  148.           case CANCEL:
  149.             DisposDialog(eviddlg);
  150.             return;
  151.  
  152.       /* Reset to the defaults.  Note these must duplicate the real initial values */      
  153.       case DEFAULTS:
  154.             SetDlgItemText (eviddlg,Res_DItem_EvidDepth,   "8");
  155.             SetDlgItemValue(eviddlg,Res_DItem_AnyEvidence, TRUE);        
  156.             SetDlgItemValue(eviddlg,Res_DItem_SilentFail,  TRUE);
  157.             break;        
  158.         
  159.       case Res_DItem_AnyEvidence:
  160.       case Res_DItem_SilentFail:
  161.         InvertDlgItemValue(eviddlg,itemhit);
  162.          break;
  163.         }
  164.     }
  165. }
  166.  
  167.  
  168. /*
  169.     A structure to hold settings and defaults.
  170. */
  171.  
  172.  
  173. struct Settings
  174. {
  175.   short        item;        /* Item                  */
  176.   int        *value;        /* Address of its value  */
  177.   int       defaults;    /* Default for this item */
  178. };
  179.  
  180.  
  181.  
  182. /*
  183.     Settings for the arcana dialog.
  184. */
  185.  
  186.  
  187. static struct Settings Arcana [] =
  188. {
  189.   {Res_DItem_LitErrs,     &literateErrors,    TRUE},    
  190.   {Res_DItem_OptFns,      &andorOptimise,    TRUE },    
  191.   {Res_DItem_FirstErr,    &failOnError,        TRUE},    
  192.   {Res_DItem_TopLevelAmb, &catchAmbigs,        FALSE},    
  193.   {Res_DItem_PattConf,    &useConformality,    TRUE },    
  194.   {Res_DItem_OverSings,   &overSingleton,    TRUE },    
  195.   {Res_DItem_KindExpert,  &kindExpert,        FALSE }    
  196. };
  197.  
  198.  
  199.  
  200. /*
  201.     The arcana dialog handles obscure, but possibly useful Gofer options.
  202. */
  203.  
  204. doarcanadialog()
  205. {
  206.   DialogPtr arcanadlg;
  207.   short itemhit;
  208.   int i;
  209.  
  210.   /* Set the cursor */
  211.   SetCursor(&(qd.arrow));
  212.   
  213.   /* Initialise the dialog */  
  214.   arcanadlg = GetNewDialog(Res_Dlg_Arcana,nil,(WindowPtr) -1);
  215.   
  216.   /* Set Check Boxes */
  217.   for(i =0; i < sizeof(Arcana)/sizeof(struct Settings); ++i)
  218.     SetDlgItemValue(arcanadlg, Arcana[i].item, *(Arcana[i].value));    
  219.   
  220.   /* Now show the window */
  221.   ShowWindow(arcanadlg);
  222.  
  223.   /* Highlight the default button */
  224.   highlightDefault(arcanadlg);
  225.  
  226.   for(;;)
  227.     {
  228.       ModalDialog((ModalFilterProcPtr) NIL,&itemhit);
  229.       switch(itemhit)
  230.         {
  231.           case OK:
  232.            for(i =0; i < sizeof(Arcana)/sizeof(struct Settings); ++i)
  233.           *(Arcana[i].value) = GetCtlValue(getctlhandle(Arcana[i].item,arcanadlg));
  234.            
  235.           case CANCEL:
  236.             DisposDialog(arcanadlg);
  237.             return;
  238.       
  239.       case DEFAULTS:
  240.            for(i =0; i < sizeof(Arcana)/sizeof(struct Settings); ++i)
  241.           SetDlgItemValue(arcanadlg, Arcana[i].item, Arcana[i].defaults);    
  242.             break;        
  243.         
  244.       case Res_DItem_LitErrs:
  245.       case Res_DItem_OptFns:
  246.       case Res_DItem_FirstErr:
  247.       case Res_DItem_TopLevelAmb:
  248.       case Res_DItem_PattConf:
  249.       case Res_DItem_OverSings:
  250.       case Res_DItem_KindExpert:
  251.         InvertDlgItemValue(arcanadlg,itemhit);
  252.          break;
  253.         }
  254.     }
  255. }
  256.  
  257.  
  258. /*
  259.    Settings for the memory dialog.
  260.  
  261.    On startup, the first item in the array will be highlighted: this should 
  262.    be the first item in the dialog or it will look odd.
  263. */
  264.  
  265. static struct Settings MemDlg [] =
  266. {
  267.     {Res_DItem_HeapPC,      &HeapPC,    DEFAULT_HEAP_PERCENTAGE},
  268.     {Res_DItem_StackSize,   &Num_stack,    NUM_STACK},
  269.     {Res_DItem_Names,       &Num_name,    NUM_NAME},
  270.     {Res_DItem_Classes,     &Num_classes,     NUM_CLASSES},    
  271.     {Res_DItem_Instances,   &Num_insts,    NUM_INSTS},    
  272.     {Res_DItem_Tycons,      &Num_tycon,    NUM_TYCON},    
  273.       {Res_DItem_Tyvars,      &Num_tyvars,    NUM_TYVARS},    
  274.       {Res_DItem_Offsets,    &Num_offsets,    NUM_OFFSETS},
  275.       {Res_DItem_Addresses,   &Num_addrs,    NUM_ADDRS},
  276.       {Res_DItem_Fixups,    &Num_fixups,    NUM_FIXUPS},
  277.       {Res_DItem_Syntax,    &Num_syntax,    NUM_SYNTAX},
  278.       {Res_DItem_Selectors,   &Num_selects,    NUM_SELECTS},
  279.     {Res_DItem_HeapSize,    &heapSize,    DEFAULTHEAP}
  280. };    
  281.  
  282. /* Which of the above are the Heap Percentage item and the Heap Size item */
  283. #define    HeapPCItem    0
  284. #define    HeapSizeItem    (sizeof(MemDlg)/sizeof(struct Settings) - 1)
  285.  
  286. domemorydialog()
  287. {
  288.   DialogPtr memdlg;
  289.   short itemhit;
  290.   int i;
  291.   int oldHeapPC = HeapPC;
  292.  
  293.   /* Set the cursor */
  294.   SetCursor(&(qd.arrow));
  295.   
  296.   /* Initialise the dialog */  
  297.   memdlg = GetNewDialog(Res_Dlg_Memory,nil,(WindowPtr) -1);
  298.   
  299.   for(i = sizeof(MemDlg)/sizeof(struct Settings)-1; i >= 0; --i)
  300.     SetDlgItemETVal(memdlg, MemDlg[i].item, *(MemDlg[i].value));
  301.     
  302.   MemDlg[HeapSizeItem].defaults = *(MemDlg[HeapSizeItem].value);
  303.  
  304.   /* Now show the window */  
  305.   ShowWindow(memdlg);
  306.  
  307.   /* Highlight the default button */
  308.   highlightDefault(memdlg);
  309.  
  310.   for(;;)
  311.     {
  312.       modal:
  313.       ModalDialog((ModalFilterProcPtr) NIL,&itemhit);
  314.       switch(itemhit)
  315.         {
  316.           case OK:
  317.             for(i = sizeof(MemDlg)/sizeof(struct Settings)-1; i >= 0; --i)
  318.           if(!GetDlgItemETVal(memdlg, MemDlg[i].item, MemDlg[i].value) ||
  319.              MemDlg[i].value < 0)
  320.             {
  321.           SysBeep(1);
  322.           /* Goto is necessary here, since break would only exit the for loop */
  323.           goto modal;
  324.         }
  325.  
  326.         /* Keep the heap percentage sensible */
  327.         if(*(MemDlg[HeapPCItem].value) > 99)
  328.           {
  329.             StopAlert(Res_HeapPCTooHigh_Alert,NIL);
  330.         HeapPC = oldHeapPC;
  331.            SetDlgItemETVal(memdlg, MemDlg[HeapPCItem].item, HeapPC);
  332.         break;
  333.           }
  334.         
  335.           case CANCEL:
  336.             DisposDialog(memdlg);
  337.             return;
  338.       
  339.       case DEFAULTS:
  340.             for(i = sizeof(MemDlg)/sizeof(struct Settings)-1; i >= 0; --i)
  341.                SetDlgItemETVal(memdlg, MemDlg[i].item, MemDlg[i].defaults);
  342.             break;        
  343.         
  344.       default:
  345.          break;
  346.         }
  347.     }
  348. }
  349.  
  350.